﻿using System.Globalization;
using KinonekoSoftware.Foundation.UI.Media;
using KinonekoSoftware.Foundation;

namespace KinonekoSoftware.Foundation.UI.Converters
{
#if AVALONIA

    using Avalonia.Data.Converters;
    
    public class StringCombinationConverter  : IMultiValueConverter
    {
        
        public object Convert(IList<object> values, Type targetType, object parameter, CultureInfo culture)
        {
            
            var array = values.Where(x => x is not null)
                             .Select(x => x.ToString());
            var sb = Pool.GetStringBuilder();
            foreach (var str in array)
            {
                sb.Append(str);
            }
            var s = sb.ToString();
            Pool.Return(sb);
            return s;
        }
    }
#else
    using System.Windows.Data;
    
    public class StringCombinationConverter  : IMultiValueConverter
    {
        
        public object Convert(object[] values, Type targetType, object parameter, CultureInfo culture)
        {
            var array = values.Where(x => x is not null)
                             .Select(x => x.ToString());
            var sb = Pool.GetStringBuilder();
            foreach (var str in array)
            {
                sb.Append(str);
            }
            var s = sb.ToString();
            Pool.Return(sb);
            return s;
            
        }
        
        public object[] ConvertBack(object value, Type[] targetTypes, object parameter, CultureInfo culture)
        {
            throw new NotSupportedException();
        }
    }
#endif

    public class StringToBrushConverter  : IValueConverter
    {
        public object Convert(object value, Type targetType, object parameter, CultureInfo culture)
        {
            var v = value?.ToString();
            return MediaFactory.ToSolidColorBrush(v);
        }
        
        public object ConvertBack(object value, Type targetType, object parameter, CultureInfo culture)
        {
            return value?.ToString();
        }
    }
    
    

}